home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / TravelingSalesman / Source_code / drawingFuncs.psw < prev    next >
Encoding:
Text File  |  1991-08-26  |  1.8 KB  |  93 lines

  1. /*
  2.  * drawingFuncs.psw  
  3.  *
  4.  * You may freely copy, distribute, and reuse the code in this example.
  5.  * NeXT disclaims any warranty of any kind, expressed or implied, as to its
  6.  * fitness for any particular use.
  7.  *
  8.  */ 
  9.  
  10. defineps loadPSProcedures()
  11.     /xpos 0 def
  12.     /ypos 0 def
  13.     /ticklength [8 2 2 2 2 5 2 2 2 2] def
  14.  
  15.     % x 
  16.     /getticklength {10 idiv 10 mod abs ticklength exch get} def
  17.  
  18.  
  19.     % x y length     
  20.     /vtick { moveto 0 exch rlineto stroke } def
  21.     /htick { moveto 0 rlineto stroke } def
  22.     
  23.     % x     
  24.     /increase-x {/xpos xpos 10 add def} def
  25.     /decrease-x {/xpos xpos 10 sub def} def
  26.  
  27.     % y     
  28.     /increase-y {/ypos ypos 10 add def} def
  29.     /decrease-y {/ypos ypos 10 sub def} def
  30. endps
  31.  
  32. defineps drawCircle(float x, y, radius)
  33.     % describe the path of a circle
  34.     newpath
  35.     x y radius 0 360 arc
  36.     closepath
  37.     stroke
  38. endps
  39.  
  40. defineps join(float x1, y1,x2,y2)
  41. % draw a line
  42. newpath 
  43. x1 y1 moveto
  44. x2 y2 lineto
  45. stroke
  46. endps
  47.  
  48. defineps drawAxes(float x, y, width, height)
  49.     gsave
  50.         % set max and min of visible area
  51.         /xmax x width add 1 sub def
  52.         /ymax y height add def
  53.         /ymin y 1 add def
  54.         /xpos 0 def
  55.         /ypos 0 def
  56.  
  57.         % draw border
  58.         x ymin moveto
  59.         x ymax lineto
  60.         xmax ymax lineto
  61.         xmax ymin lineto
  62.         closepath
  63.         stroke
  64.  
  65.         % now draw axes
  66.         x 0 moveto
  67.         xmax 0 lineto
  68.         stroke
  69.         0 ymin moveto
  70.         0 ymax lineto
  71.         stroke
  72.         0 0 moveto
  73.         % draw the pos x ticks
  74.         {xpos xmax le
  75.             {xpos getticklength neg xpos 0 vtick increase-x}{exit} ifelse
  76.         } loop
  77.         % draw the neg x ticks
  78.         0 0 moveto
  79.         {xpos x ge
  80.             {xpos getticklength neg xpos 0 vtick decrease-x}{exit} ifelse
  81.         } loop
  82.         % draw the pos y ticks
  83.         0 0 moveto
  84.         {ypos ymax le
  85.             {ypos getticklength neg 0 ypos htick increase-y}{exit} ifelse
  86.         } loop
  87.         % draw the neg y ticks
  88.         0 0 moveto
  89.         {ypos ymin ge
  90.             {ypos getticklength neg 0 ypos htick decrease-y}{exit} ifelse
  91.         } loop
  92.     grestore
  93. endps